package com.hong.cloud.mall.practice.common.util;

import com.hong.cloud.mall.practice.common.common.Constant;
import org.apache.tomcat.util.codec.binary.Base64;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 描述：MD5工具类
 */

public class MD5Utils {
    // 生成MD5，用于密码加密
    public static String getMD5Str(String str) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        return Base64.encodeBase64String(md5.digest((str + Constant.SALT).getBytes()));
    }
    // 测试生成的MD5值
    public static void main(String[] args) throws NoSuchAlgorithmException {
        System.out.println(getMD5Str("123456"));
    }
}
